<script>
	// 域名
	const hostname = "https://www.huayunzhi2025.com/api"    //接口地址
	// const hostname = "http://192.168.0.40:8081"
	//图片地址
	const imgBaseUrl = "https://huayunzhi2025.oss-cn-shanghai.aliyuncs.com"
	export default {
		hostname,
		imgBaseUrl,
		data() {
			return {
				hasProcessedLaunchParams: false, // 标记是否已处理启动参数
				lastProcessedParams: null // 记录上次处理的参数
			}
		},
		onLaunch: function(options) {
			console.log('App Launch')
			console.log("options ------ ",options)
			if(options) {
				this.getCodeParams(options)
				this.hasProcessedLaunchParams = true
				this.lastProcessedParams = JSON.stringify(options.query || {})
			}
			// 初始化购物车角标
			const cartCount = uni.getStorageSync('cartCount') || 0;
			if (cartCount > 0) {
				uni.setTabBarBadge({
					index: 3,
					text: cartCount.toString()
				});
			}
			const updateManager = uni.getUpdateManager();
			  updateManager.onCheckForUpdate(function (res) {
				// 请求完新版本信息的回调
				// console.log(res.hasUpdate);
			  });
			  // 下载新版本
			  updateManager.onUpdateReady(function () {
				uni.showModal({
				  title: "更新提示",
				  content: "新版本已经准备好，为了更好体验请更新！",
				  success(res) {
					if (res.confirm) {
					  // 重启应用
					  updateManager.applyUpdate();
					}
				  },
				});
			  });
			  // 新版本下载失败
			  updateManager.onUpdateFailed(function (res) {
				// 新的版本下载失败
				uni.showModal({
				  title: "已经有新版本了",
				  content: "新版本已经上线啦~，请您删除当前小程序，重新搜索打开！",
				});
			  });
		},
		onShow: function(options) {
			if(options) {
				const currentParams = JSON.stringify(options.query || {})
				
				// 如果是从后台恢复且参数相同，则跳过处理
				if (this.hasProcessedLaunchParams && currentParams === this.lastProcessedParams) {
					console.log('从后台恢复，跳过参数处理')
					return
				}
				
				this.getCodeParams(options)
				this.lastProcessedParams = currentParams
			}
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			 // 获取二维码参数
			 getCodeParams(item) {
			 	if (item.query) {
			 		const param = decodeURIComponent(item.query.scene);
			 		const parentId = param.split("=")[1]
			 		if (!uni.getStorageSync('token') && parentId) {
			 			uni.navigateTo({
			 				url: '/subPackages/mine/login/login?parentId=' + parentId
			 			})
			 		}
			 	}
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	
	/* 修改轮播图的默认小圆点 */
	wx-swiper .wx-swiper-dot {
		width: 13rpx!important;
		height: 13rpx!important;
		border-radius: 50%!important;
		margin-bottom: 12rpx!important;
		background-color: #fff!important;
	}
	wx-swiper .wx-swiper-dot-active {
		width: 30rpx!important;
		height: 12rpx!important;
		border-radius: 10rpx!important;
		background-color: #009966!important;
	}
	wx-swiper .uni-swiper-dots-horizontal  {
		position: absolute;
		right: 20rpx !important;
		bottom: 20rpx !important;
	}
	uni-swiper .uni-swiper-dots-horizontal  {
		right: 20rpx !important;
	}
</style>
